$(function(){
 $('#choice_city_button').button({
            icons: {
                secondary: "ui-icon-triangle-1-s"
            }
        }).click(function() { $('#choice_city_dialog').dialog( "open" );});

//		$("#choice_city_button").css("height","30px");
$(".ui-button-text").css("padding","2px 20px");

  $('#choice_city_dialog').dialog({
					autoOpen: false,
					draggable: false,
					position: [483,60],
					minWidth: 440,
					minHeight: 180
				});
$("#choice_city_dialog").css("font-size","12px");		

$( "#choice_city_dialog").dialog( "option", "closeText", '关闭' );
$(".ui-dialog-titlebar").css("padding","2px 10px");
$(".ui-dialog-titlebar").css("font-weight","normal");
$(".ui-dialog-titlebar").css("font-size","12px");

var cityB = document.getElementById("cityName").value;
var cityName = encodeURIComponent(cityB);
//console.log("cityName:"+cityName);
//alert(cityB+"cityName0:"+cityName+"11111111" +encodeURIComponent(cityName));
$('#search_button').button().click(function() { 
	  var key=document.getElementById("key").value;	 
	  if(key.length>0){
	  loadDeals('/tuan/getDeals?cityName='+cityName+"&key=" + key);
	  }
	 });
		
//$("#header_index").addClass('header_current_a');


//createPage("dealListPageIndex");
loadDeals('/tuan/getDeals?cityName=' + cityName);

/*	// 创建分页
	$("#pagination_deal_list").paging(58, {
        perpage: 3,
        lapping: 0,
        page: null, // we await hashchange() event
        onSelect: function (page) {



                return true; // locate!
        }
});*/


$("#login_a").click(function(){
	$("#login").zxxbox( {
        title: "登陆界面"	
    });		
	$("#loginBtn").click(function(){
		 $("#login_tips").html(""); 
		 var email = $("#email").val();
		 var password = $("#password").val();
		  $.post("/json/login",{email:email, password: password},function(data){
			  data = eval("("+data+")");
			  if(data.tag > 0){
				  window.location.reload();
				  //$("#login_span").html(data.email); 
				  // $.zxxbox.hide();
			  }else{
				  $("#login_tips").html("用户名和密码不匹配。"); 
			  }
			 
		  });
		
	});
	$("#cancelBtn").click(function(){
		$.zxxbox.hide();						   
	});
});

$("#register_a").click(function(){
	$("#register").zxxbox( {
        title: "注册界面"	
    });		
	$("#registerBtn").click(function(){
		 $("#register_tips").html(""); 
		 var email = $("#r_email").val();
		 var password1 = $("#r1_password").val();
		 var password2 = $("#r2_password").val();
		 var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		 var validata = 1;
		 if(!myreg.test(email)){
			 $("#register_tips").html("邮箱地址不对，请核实后输入。"); 
			 validata --;
		 }
		 if(validata > 0 && password1 != password2){
			 $("#register_tips").html("两次输入密码不匹配，请核实后输入。"); 
			 validata --;
		 }
		 if( validata>0){
		 $.post("/json/register",{email:email, password: password1},function(data){
			  data = eval("("+data+")");
			  console.log(data);
			  if(data.tag > 0){
				  window.location.reload();
				  //$("#login_span").html(data.email); 
				  // $.zxxbox.hide();
			  }else{
				  $("#register_tips").html("用户名已经存在。");
			  }
			 
		  });
		 }
		
	});
	$("#registerCancelBtn").click(function(){
		$.zxxbox.hide();						   
	});
});


$("#logout_a").click(function(){
	$.post("/json/logout");	
	 window.location.reload();
});


})


